'''
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with self work for additional information
 * regarding copyright ownership.  The ASF licenses self file
 * to you under the Apache License, Version 2.0 (the
 * "License") you may not use self file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http:#www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
'''


#import org.apache.jena.assembler.exceptions.AssemblerException;
#import org.apache.jena.rdf.model.*;

'''
 * Exception used to report that the object of a statement is not a Resource.
 * The subject of the exception is treated as the root object. The nature of the
 * unsuitability is (currently) not described.
'''
class BadObjectException(AssemblerException):
    protected final RDFNode object

    # param Statement s
    def __init__(self, s):
        super().__init__(s.getSubject(), makeMessage(s))
        self.object = s.getObject()
    

    # param Statement s
    # result static String
    def makeMessage(self, s):
        RDFNode subject = s.getObject()
        return
                "the " + typeOf(subject) + " " + nice(subject)
                        + " is unsuitable as the object of a " + nice(s.getPredicate())
                        + " statement"
    

    # param RDFNode x
    # result static String
    def typeOf(self, x):
        return x.isAnon() ? "bnode" else x.isLiteral() ? "literal" else "resource"
    

    # param 
    # result RDFNode
    def getObject(self):
        return object
    

